package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import controller.Controller;

import model.BuildingBlock;
import model.Output;

/**
 * Output megjelenítéséért felelős osztály
 * JPanel és MouseListener leszármazás és implementálás a kattinthatóságért
 * @author radioactivebee
 *
 */
public class OutputView extends JPanel implements Paintable, MouseListener {

	private static final long serialVersionUID = 1L;
	private int x;
	private int y;
	private Output output;
	private model.BuildingBlock bb; 
	
	public static boolean darken = false;
		
	public OutputView(int x, int y, Output output, BuildingBlock outBlock){
		this.x = x;
		this.y = y;
		
		this.output = output;
		this.bb = outBlock;
		
		setBounds(this.x-5, this.y-5, 10, 10);
		addMouseListener(this);
	}
	
	@Override
	public void mouseClicked(MouseEvent e){
		//super.mousePressed(e);
		if(Controller.verbose){
			System.out.println("outputview mouse listener invoked");
		}
		Controller.getInstance().outputClicked(this);
	}
	
	@Override
	public void paint(Graphics g) {
		g.setColor(Color.BLACK);
		g.drawOval(x-5, y-5, 10, 10);
		if (output.getState().equals(false)){
			g.setColor(Color.WHITE);
		} else {
			g.setColor(Color.RED);			
		}		
		if(OutputView.darken){
			g.setColor(g.getColor().darker());
		}
		g.fillOval(x-5, y-5, 10, 10);		
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Output getModel(){
		return output;
	}
	
	public model.BuildingBlock getOutBlock(){
		return this.bb;
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
	}

	@Override
	public void mousePressed(MouseEvent arg0) {	
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
	}
}
